package ming.model.type;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@SuppressWarnings("serial")
@Entity
@Table(name = "T_TOBACCO_MODULE", schema = "")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Module implements java.io.Serializable {

	private String pid;// 虚拟属性，用于获得当前资源的父资源ID
	private String id;
	private String bussinessName;
	private String bussinessCode;
	private String bussinessType;
	private String icon;
	private String url;
	private Integer seq;
	private Integer bussinessStatus;
	private String description;
	private Date createdatetime;
	private Date updatedatetime;
	private Module module;
	private Set<Module> modules = new HashSet<Module>(0);

	@Id
	@Column(name = "ID", unique = true, nullable = false, length = 36)
	public String getId() {
		if (!StringUtils.isBlank(this.id)) {
			return this.id;
		}
		return UUID.randomUUID().toString();
	}

	public void setId(String id) {
		this.id = id;
	}
	

	@Column(name = "bussinessName", length = 200)
	public String getBussinessName() {
		return this.bussinessName;
	}

	public void setBussinessName(String bussinessName) {
		this.bussinessName = bussinessName;
	}


	@Column(name = "bussinessCode", length = 200)
	public String getBussinessCode() {
		return this.bussinessCode;
	}

	public void setBussinessCode(String bussinessCode) {
		this.bussinessCode = bussinessCode;
	}


	@Column(name = "bussinessType", length = 200)
	public String getBussinessType() {
		return this.bussinessType;
	}

	public void setBussinessType(String bussinessType) {
		this.bussinessType = bussinessType;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "updatedatetime", length = 7)
	public Date getUpdatedatetime() {
		if (this.updatedatetime != null)
			return this.updatedatetime;
		return new Date();
	}

	public void setUpdatedatetime(Date updatedatetime) {
		this.updatedatetime = updatedatetime;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "createdatetime", length = 7)
	public Date getCreatedatetime() {
		if (this.createdatetime != null)
			return this.createdatetime;
		return new Date();
	}

	public void setCreatedatetime(Date createdatetime) {
		this.createdatetime = createdatetime;
	}



	@Column(name = "url", length = 200)
	public String getUrl() {
		return this.url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "description", length = 200)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "icon", length = 100)
	public String getIcon() {
		return this.icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@Column(name = "seq", precision = 8, scale = 0)
	public Integer getSeq() {
		return this.seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	@Column(name = "bussinessStatus", precision = 8, scale = 0)
	public Integer getBussinessStatus() {
		return this.bussinessStatus;
	}

	public void setBussinessStatus(Integer bussinessStatus) {
		this.bussinessStatus = bussinessStatus;
	}

	
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MODULE_ID")
	public Module getModule() {
		return module;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "module", cascade = CascadeType.ALL)
	public Set<Module> getModules() {
		return modules;
	}

	public void setModules(Set<Module> modules) {
		this.modules = modules;
	}

	@Transient
	public String getPid() {
		if (module != null && !StringUtils.isBlank(module.getId())) {
			return module.getId();
		}
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}
}
